
var Base = require("../common/base");
var AdminModels = require("../../models/admin/admin");
var express = require('express');

class Admin extends Base{
    constructor(){
        super();
        
        this.login = this.login.bind(this);
    }

    async login(req,res,next){
        var param = req.query || req.params;
        
        var user = {
            username : req.body.username,
            password : req.body.password
        }
        // var username = param.username;
        // var password = param.password;
        // console.log(username);
        // console.log(user);
        AdminModels.checkPassword(user).then(message=>{

            res.cookie("username", user.username, { expires: new Date(Date.now() + this.get_cookie_time()), httpOnly: true });
            res.cookie("cookie", this.MD5(user.username), { expires: new Date(Date.now() + this.get_cookie_time()), httpOnly: true });
            
            res.redirect("/index");
		},error=>{
		    res.redirect("/login");
		})
        // AdminModels.checkPassword(username,password,function(){
        //     res.send("xxx");
        // },function(msg){
            
        // });
    }

    async passModify(req,res,next){

    }
}

module.exports = new Admin();